#include "Timer.h"

#include "SDL/SDL.h"

void Timer_start(Timer_t * Timer)
{
	Timer->start = SDL_GetTicks();
	Timer->started = 1;
	Timer->paused = 0;
}

int Timer_now(Timer_t * Timer)
{
	if (Timer->started) {
		if (Timer->paused)
			return Timer->pause;
		else
			return (SDL_GetTicks() - Timer->start);
	}
	return 0;
}

void Timer_pause(Timer_t * Timer)
{
	if (Timer->started && !Timer->paused) {
		Timer->paused = 1;
		Timer->pause = SDL_GetTicks() - Timer->start;
	}
}

void Timer_unpause(Timer_t * Timer)
{
	if (Timer->paused) {
		Timer->paused = 0;
		Timer->start = SDL_GetTicks() - Timer->pause;
		Timer->pause = 0;
	}
}
